﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Security.Permissions;

namespace Model.Crafters
{
    [Serializable]
    public class Skill : INotifyPropertyChanged, ISerializable
    {
        private int _SkillPoints; //skillpoints
        private String _Name;
        private SkillTypes _SkillType;

        //craftmanship, flair, enchanting, spellcrafting, inventing etc.

        public Skill() { } //empty ctor for serialization

        protected Skill(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
                throw new System.ArgumentNullException("info");
            //Console.WriteLine("Serialization ctor in Skill");            
            SkillType = (SkillTypes)info.GetValue("SkillType", typeof(SkillTypes));            
            Name = (String)info.GetValue("Name", typeof(String));
            SkillPoints = (int)info.GetValue("SkillPoints", typeof(int));
        }

        public enum SkillTypes
        {
            Craftmanship,
            Flair,
            Enchanting,
            Spellcrafting,
            Inventing
        }

        public SkillTypes SkillType
        {
            get { return _SkillType; }
            set
            {
                _SkillType = value;
                NotifyPropertyChanged("SkillType");
            }
        }

        public String Name
        {
            get { return _Name; }
            set
            {
                _Name = value;
                NotifyPropertyChanged("Name");
            }
        }

        public int SkillPoints
        {
            get { return _SkillPoints; }
            set
            {
                _SkillPoints = value;
                NotifyPropertyChanged("SkillPoints");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        public override String ToString()
        {
            return Name + ": " + SkillPoints;
        }

        [SecurityPermission(SecurityAction.LinkDemand,
        Flags = SecurityPermissionFlag.SerializationFormatter)]
        public virtual void GetObjectData(
        SerializationInfo info, StreamingContext context)
        {
            if (info == null)
                throw new System.ArgumentNullException("info");
            //Console.WriteLine("GetObjectData in Skill");
            info.AddValue("SkillType", SkillType);
            info.AddValue("Name", Name);
            info.AddValue("SkillPoints", SkillPoints);
        }
    }
}
